<template>
    <div>
        <a href="/add">会员新增</a>
        <h1>首页-会员列表</h1>
        <table class="table">
            <thead>
                <tr>
                    <td>id</td>
                    <td>name</td>
                    <td>houbbyCount</td>
                    <td>操作</td>
                </tr>
            </thead>
            <tbody>
                <tr v-for="d in data">
                    <td>{{d.id}}</td>
                    <td>{{d.name}}</td>
                    <td>{{d.houbbyCount}}</td>
                    <td><input type="button" value="删除" @click="del(d.id)"></td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import { ref, onMounted} from 'vue';
import axios from 'axios';
import { useRouter} from 'vue-router';
const data=ref([]);
onMounted(()=>{
    getdata();
})
const getdata=()=>{
    axios.get("https://localhost:7096/api/Member/GetMembers").then(res=>{
        data.value=res.data;
    })
}
const del=(val:any)=>{
    if(confirm('确定删除吗'))
    axios.delete("https://localhost:7096/api/Member/DeleteMember",{params:{id:val}}).then(res=>{
        if(res.data>0){
            alert("删除成功")
            getdata();
        }
        else{
            alert("删除失败")
        }
    })
}
</script>

<style scoped>

</style>